<?php
namespace app\index\controller;

use app\index\common\Common;
use app\index\model\User;
use think\Controller;
use think\Exception;
use think\Request;
class BaseController extends Controller
{
    /**
     * @var array 用户session数据
     * @param string name
     * @param int id
     * @param int role
     */
    public $user_session;
    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this->checkUserLogin();
        $this->user_session=session('Login_user');
    }

    public function _empty(){
        return json(['code'=>404,'msg'=>'page not found'],404);
    }

    /**
     *
     */
    protected function checkUserLogin(): void
    {
        $user=session('Login_user');
        if (!is_array($user) || empty($user)) {
            http_response_code('200');
            exit(json_encode(['code'=>401,'msg'=>'请先登录']));
        }
    }

    public function sendWSMessage($user,$ws_id,$message){
        Common::sendWSMessage($user,$ws_id,$message);
    }
}